
<template>
  <div class="main-container">
    <div class="filtrate-bar">
      <div class="title-box">
        <div class="icon-box">
          <span class="iconfont icon-yuangong" />
        </div>
        <span class="text" style="margin-right: 10px">人员流失情况</span>
        <a-radio-group v-if="isAllData" v-model="parentId" button-style="solid" @change="getDepartments">
          <a-radio-button value="1"> 全部 </a-radio-button>
          <a-radio-button value="73"> 总部 </a-radio-button>
        </a-radio-group>
        <span v-if="isAllData" class="search-label" style="margin-left: 10px">部门：</span>
        <a-select v-if="isAllData" v-model="departmentIds" mode="multiple" style="width: 300px" placeholder="请选择" @change="handleDepartmentChange">
          <a-select-option v-for="item in departmentIdList" :key="item.departmentId">
            {{ item.name }}
          </a-select-option>
        </a-select>
        <a-month-picker
          style="width: 195px; margin-left: 10px"
          placeholder="请选择开始日期"
          v-model="fromDate"
          @change="handleFromDateChange"
          :format="dateFormat"
        />
        <span class="query-group-split-cust"> - </span>
        <a-month-picker
          style="width: 195px"
          placeholder="请选择结束日期"
          v-model="thruDate"
          @change="handleThruDateChange"
          :format="dateFormat"
        />
        <!-- <j-date
        style="width: 195px"
          date-format="YYYY-MM"
          placeholder="请选择开始时间"
          class="query-group-cust"
          v-model="params.fromDate"
        ></j-date>
        
        <j-date
        style="width: 195px"
          date-format="YYYY-MM"
          placeholder="请选择结束时间"
          class="query-group-cust"
          v-model="params.thruDate"
        ></j-date> -->
        <a-button type="primary" @click="getDataList" style="margin-left: 10px" icon="search">查询</a-button>
      </div>
    </div>

    <div class="content">
      <div class="table-content">
        <div class="handle-bar">
          <!--
          <a-button class="export-btn" type="primary" icon="download" @click="handleExportXls">导出</a-button>
          -->
        </div>
        <a-table :columns="columns" :data-source="dataList" :pagination="false" bordered :scroll="{ y: 550 }">
          <template slot="departmentName" slot-scope="text, record">
            <a-tooltip placement="top">
              <template slot="title">
                <span>{{ record.departmentName }}</span>
              </template>
              <span class="ellipsis" style="text-align: center; width: 100%"
                ><a @click="() => showReason(record.departmentId)">{{ record.departmentName }}</a></span
              >
            </a-tooltip>
          </template>
        </a-table>
      </div>
    </div>

    <resign-reason ref="resignReason"></resign-reason>
  </div>
</template>

<script>
import JDate from '@/components/jeecg/JDate.vue'
import JCategorySelect from '@/components/jeecg/JCategorySelect'
import { postAction, getAction, downFile } from '@/api/manage'
import ResignReason from './components/resignReason'
export default {
  name: 'statistics',
  components: {
    JDate,
    ResignReason,
    JCategorySelect,
  },

  data() {
    return {
      isAllData: this.$store.getters.buData == 'allhrdata' ? true : false,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 100,
          align: 'center',
          customRender: function (t, r, index) {
            if (r.rank == '汇总') {
              return '汇总'
            } else {
              return parseInt(index) + 1
            }
          },
        },
        {
          title: 'BU',
          align: 'center',
          width: 300,
          dataIndex: 'departmentName',
          scopedSlots: { customRender: 'departmentName' },
        },
        {
          title: '离职人数',
          align: 'center',
          width: 300,
          dataIndex: 'quitNum',
        },
        {
          title: '在职人数',
          align: 'center',
          width: 300,
          dataIndex: 'onlineNum',
        },
        {
          title: '离职率',
          align: 'center',
          dataIndex: 'resignRate',
        },
      ],
      dataList: [],
      dateFormat: 'YYYY-MM',
      fromDate: null,
      thruDate: null,
      departmentIds: [],
      departmentIdList: [],
      parentId: '1',
      params: {
        ids: '',
        fromDate: null,
        thruDate: null,
        pageSize: 100,
      },
      url: {
        getResignReport: '/online/api/getResignReport',
        listHrDepartmentByAllHrData: '/online/api/listHrDepartmentByAllHrData',
        exportXlsUrl: '/online/api/export/exportXlsGraphReport',
      },
    }
  },
  computed: {},
  //watch: {},
  mounted() {
    this.getDepartments()
  },
  methods: {
    getDepartments() {
      this.departmentIds = []
      getAction(this.url.listHrDepartmentByAllHrData, {parentId: this.parentId}).then((res) => {
        if (res.success) {
          this.departmentIdList = res.result
        }
      })
      this.getDataList()
    },
    handleDepartmentChange(e) {
      this.departmentIds = e
    },
    handleFromDateChange(date, dateString) {
      this.params.fromDate = dateString
    },
    handleThruDateChange(date, dateString) {
      this.params.thruDate = dateString
    },
    getDataList() {
      this.params.parentId = this.parentId
      this.params.ids = this.departmentIds.join(';')
      if(!this.isAllData){
        this.params.userLoginDepartmentId = this.$store.getters.departmentId
      }
      getAction(this.url.getResignReport, this.params).then((res) => {
        if (res.success) {
          this.dataList = res.result.records
        }
      })
    },

    /**
     * 导出点击
     */
    exportClick() {
      this.requestExportInfo(biCustomerTotalListExportAPI, this.listPostParams)
    },
    showReason(id) {
      let params = {}
      if (id) {
        params.departmentId = id
      } else {
        params.departmentId = 'all'
      }
      params.fromDate = this.params.fromDate
      params.thruDate = this.params.thruDate
      this.$refs.resignReason.show(params)
    },
  },
}
</script>


<style lang="less" scoped>
.main-container {
  border: 1px solid #e6e6e6;
  border-radius: 2px;
  background-color: white;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.filtrate-bar {
  background-color: white;
  padding: 15px 20px 5px 20px;
  margin-right: 15px;
  line-height: 34px;
  .icon-box {
    width: 34px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #2362fb;
    background-color: #dfe8ff;
    border-radius: 50%;
    margin-right: 10px;
    float: left;
  }
  .text {
    font-size: 17px;
    font-weight: 700;
  }
}

.content {
  height: calc(100% - 54px);
  overflow-y: auto;
  padding: 10px 0;
}

.content-title {
  padding: 10px 20px 5px;
  font-size: 16px;
  color: #333;
}

.axis-content {
  padding: 20px 10% 40px;
  position: relative;
  .axismain,
  #axismain {
    margin: 0 auto;
    width: 95%;
    height: 400px;
  }
}

.table-content {
  padding: 0 60px 20px 60px;
}

.export-button {
  float: right;
  margin-right: 22px;
}

// 导出操作bug
.handle-bar {
  margin-bottom: 8px;
  text-align: right;
}

.search-box {
  padding-right: 15px;
}

.radio-box {
  padding: 0 20px;
  margin-bottom: 15px;
  /deep/ .el-radio__label {
    color: #99a9bf !important;
  }
}

.static {
  padding: 0 20px;
  margin-bottom: 10px;
  .text {
    font-size: 13px;
    color: #99a9bf;
    display: inline-block;
  }
  .text:not(:last-child) {
    margin-right: 15px;
  }
}
</style>

